<!-- 头部 -->
{include file="public/top" /}
<!-- /头部 -->
<div class="main-container" id="main-container">
    <!-- left -->
    {include file="public/left" /}
    <!-- /left -->


    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <div class="breadcrumbs" id="breadcrumbs">
                <script type="text/javascript">
                    try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
                </script>
                <ul class="breadcrumb">
                    <li>
                        <i class="ace-icon fa fa-home home-icon"></i> <a href="#">首页</a>
                    </li>
                    <li><a href="#">数据管理</a></li>
                    <li class="active">数据预览</li>
                </ul>
                <!-- #section:basics/content.searchbox -->
                <!--<div class="nav-search" id="nav-search">-->
                    <!--<form class="form-search">-->
								<!--<span class="input-icon">-->
									<!--<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />-->
									<!--<i class="ace-icon fa fa-search nav-search-icon"></i>-->
								<!--</span>-->
                    <!--</form>-->
                <!--</div>&lt;!&ndash; /.nav-search &ndash;&gt;-->
                <!-- /section:basics/content.searchbox -->
            </div>


            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <div class="page-header">
                    <div class="row">
                        <div class="col-md-6">
                            <h1>
                                我的数据源列表
                                <small>
                                    <i class="ace-icon fa fa-angle-double-right"></i>
                                    管理我创建的数据源
                                </small>
                            </h1>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <form method="post" name="thevalueform" id="theform" action="{:url('Robot/Robotlist')}" enctype="multipart/form-data" onSubmit="return validate(this)">
                            <input type="hidden" name="formhash" value="$formhash">
                            <!--<div style="margin-bottom: 20px">-->
                                <!--&lt;!&ndash;<button  class="btn btn-white btn-info" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample"><i class="ace-icon fa fa-cog bigger-119"></i>标签管理&ndash;&gt;-->
                                <!--&lt;!&ndash;</button>&nbsp;&nbsp;&nbsp;&nbsp;&ndash;&gt;-->

                                <!--ID: &nbsp;&nbsp;<input style="" size="13" class="" type="text" name="crid" >&nbsp;&nbsp;-->
                                <!--关键词: &nbsp;&nbsp;<input style="" size="13" class="" type="text" name="cname" >&nbsp;&nbsp;-->
                                <!--<input style="margin-left:20px" type="submit" name="searchsubmit" value="搜索" class="btn btn-xs btn-info btn-round input-mini">-->
                            <!--</div>-->
                            <!--<div class="collapse" id="collapseExample">-->
                                <!--<div class="formheader">-->
                                    <!--移至:-->
                                    <!--<select  style="margin-left:15px"  name="tagid" id="tagid" >-->
                                        <!--<option value=""   select="selected">请选择</option>-->
                                    <!--</select>-->
                                    <!--<input style="margin-left:20px" type="submit" name="movesubmit" value="提 交" class="btn btn-xs btn-info btn-round input-mini">-->
                                    <!--<input style="margin-left:274px" size="13" class="" type="text" name="addtag" >-->
                                    <!--<input style="margin-left:20px" type="submit" name="addsubmit" value="添加标签" class="btn btn-xs btn-info btn-round input-mini">-->
                                    <!--<button   style="margin-left:20px"  class="btn btn-xs btn-info btn-round input-mini" type="button" data-rel="tooltip" data-original-title="" onclick="window.location.href='{:url("Robot/EditTag")}'">编辑标签</button>-->
                                <!--</div>-->
                            <!--</div>-->
                            <!--<div >-->
                                <!--<div >-->
                                    <!--<ul class="nav nav-tabs" id="myTab2">-->
                                        <!--<li class="active">-->
                                            <!--<a data-toggle="tab" href="#" onclick="window.location.href=\'' . $cpurl . '?action=robots&op=mycreaterobot&tagid=0\'" aria-expanded="true">全部</a>-->
                                        <!--</li>-->



                                        <!--&lt;!&ndash;<li class="">&ndash;&gt;-->
                                            <!--&lt;!&ndash;<a data-toggle="tab" href="#" onclick="window.location.href=\'' . $cpurl . '?action=robots&op=mycreaterobot&tagid=0\'" aria-expanded="true">标签2</a>&ndash;&gt;-->
                                        <!--&lt;!&ndash;</li>&ndash;&gt;-->

                                    <!--</ul>-->
                                <!--</div>-->
                            <!--</div>-->

                        <table cellspacing="0" cellpadding="0" width="100%" class="table table-striped table-bordered table-hover">
                            <tbody>
                                <tr>
                                    <th width="40xp"><input class="ace" type="checkbox" name="chkall" onclick="checkall(this.form, 'item')"><span class="lbl"></span></th>
                                    <th>ID</th>
                                    <th >  {$Think.lang.robot_robot_name}</th>
                                    <th>{$Think.lang.robot_robot_status}<i class="fa fa-question-circle" data-rel="tooltip" data-original-title=" {$Think.lang.robot_robot_status_help}"></i></th>
                                    <th >{$Think.lang.robot_robot_dateline}</th>
                                    <th>{$Think.lang.robot_robot_robot_time}</th>
                                    <th>下次更新时间<i class="fa fa-question-circle" data-rel="tooltip" data-original-title="{$Think.lang.robot_next_run_time_tip}"></i></th>
                                    <th>{$Think.lang.robot_robot_op_select}<i class="fa fa-question-circle" data-rel="tooltip" data-original-title=" {$Think.lang.robot_robot_op_select_help} "></i></th>
                                    </tr>
                            <!--数据行-->
                                {if empty($listarr)}
                                <tr><td colspan="8" align="center" style="height:60px;color:#666;">暂无数据</td></tr>
                                {else/}
                                {volist name='listarr' id='vo' empty="暂时没有数据"}
                                <tr>
                                    <td><label><input class="ace" type="checkbox" name="item[]" value="1" /><span class="lbl"> </span><label></td>
                                    <td style="color:#454545;">{$vo.robotid}</td>
                                    <td><a href="{:url('robot/detail',array('robotid' => $vo.robotid))}">
                                        <b>{$vo.name|msubstr=0,25}
                                            {if condition="$vo.cloud_resource eq 0 "}
                                        &nbsp;<span class="label label-success label-white middle recommendtag tooltip-success" data-rel="tooltip" data-original-title="来自云端">云</span>
                                            {/if}
                                    </b></a> </td>
                                    <td id="progress{$vo.robotid}"><div style="display:inline-block; vertical-align: middle;"><div class="progress pos-rel tooltip-info" data-percent="0%" data-rel="tooltip" data-original-title=" Starting ... " style="display:none;margin-bottom:0px;width:60px;">
                                        <div class="progress-bar" style="width:0%;"></div>
                                    </div></div>{$vo.status_desc}
                                    </td>
                                    <td style="color:#454545;">{$vo.dateline|date="Y-m-d",###}</td>
                                    <td style="color:#454545;">
                                        {if condition="$vo.lasttime eq 0"}--
                                        {else /}{$vo.lasttime|date="Y-m-d",###}
                                        {/if}
                                    </td>
                                    <td style="color:#454545;">
                                        {if condition="$vo.next_run_time eq 0"}--
                                        {else /}{$vo.next_run_time}
                                        {/if}
                                    </td>
                                    <td>
                                        <button class="btn btn-mini btn-success tooltip-success runstyle  " type="button" data-rel="tooltip" data-original-title="云采集" data-robot="{$vo.robotid}" data-run="{:url('robot/startrun',[robotid=>$vo.robotid])}" data-runstop="{:url('robot/stoprun',[robotid=>$vo.robotid])}" onclick="run(this);" data-click="false"><i class="ace-icon fa fa-play "></i></button>

                                        <button class="btn btn-mini btn-warning tooltip-warning  " type="button" data-rel="tooltip" data-original-title="测试采集" onclick="window.location.href='{:url("robot/debugrobot",['robotid'=>$vo.robotid])}'"><i class="ace-icon fa fa-bug bigger-110"></i></button>
                                        <button class="btn btn-mini btn-success tooltip-success  " type="button" data-rel="tooltip" data-original-title="复制" onclick="window.location.href='{:url("Robot/Copy",array("robotid"=>$vo.robotid))}'"><i class="ace-icon fa fa-copy "></i></button>
                                        <button class="btn btn-mini btn-warning tooltip-warning  " type="button" data-rel="tooltip" data-original-title="导出规则" onclick="window.location.href='{:url("Robot/export",array("robotid"=>$vo.robotid,'robotname'=>$vo.name))}'"><i class="ace-icon fa fa-save "></i></button>
                                        <button class="btn btn-mini btn-info tooltip-info  " type="button" data-rel="tooltip" data-original-title="编辑"
                                                onclick="window.location.href='{:url("Robot/Edit",array("robotid"=>$vo.robotid))}'"><i class="ace-icon fa  fa-pencil  "></i></button>
                                    </td>
                                </tr>
                                {/volist}
                                {/if}
                            </tbody>
                        </table>
                        {$multipage}
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->




</div><!-- /.main-container -->
<script type="text/javascript">
    window.jQuery || document.write("<script src='__ADMIN__/js/jquery.js'>"+"<"+"/script>");
</script>
<script type="text/javascript">
    jQuery(function($) {
        $('[data-rel=tooltip]').tooltip();
        function GetRTime() {
            var EndTime = new Date('$thereqlogvalue[flowdeadline]');
            var NowTime = new Date();
            var t = EndTime.getTime() - NowTime.getTime();
            var d = Math.floor(t / 1000 / 60 / 60 / 24);
            var h = Math.floor(t / 1000 / 60 / 60 % 24);
            var m = Math.floor(t / 1000 / 60 % 60);
            var s = Math.floor(t / 1000 % 60);
            if (document.getElementById("t_d") && t > 0) {
                document.getElementById("t_d").innerHTML = d + "天";
                document.getElementById("t_h").innerHTML = h + "时";
                document.getElementById("t_m").innerHTML = m + "分";
                document.getElementById("t_s").innerHTML = s + "秒";
            }
        }

        setInterval(GetRTime, 1000);
    })

    function getPercent(obj){
        var robotid = [];  //URL字符串
        //查找符合条件的所有URL并以逗号分隔拼接成字符串
        $(obj).each(function(index,element){
            var id = $(element).attr('data-robot');
            robotid.push(id);
        });
        //如果没有符合条件的URL字符串就停止
        if (robotid == '') {return};
       // console.log(robotid);return;
        //请求服务器
        $.post("{:url('robot/progress')}",{'robotid':robotid},function(res){

            if (res) {
                //返回json格式的数据,URL对应的进度数
                $.each(res,function(i,v){
                    var s_btn = $("button[data-robot='"+i+"']");
                    var s_tr = $('#progress'+i);
                    if (v != false) { //如果对应的URL读取进步数则如下操作
                        s_tr.children('font').hide();
                        s_tr.children('div').children('div').show();
                        v = eval('('+v+')');
                        failvale = parseInt(v.crtcount) - parseInt(v.succount) - parseInt(v.repcount);
                        v.mpage = parseInt(v.mpage);
                        v.lpage = parseInt(v.lpage);
                        //exvalue = v.crtcount+' / '+failvale+' / '+v.lpage+' / '+v.mpage;
                        exvalue = '成功：'+v.succount+' | 重复：'+v.repcount+' | 失败：'+failvale;
                        value = v.percount;
                        width = v.percount;
                        s_tr.find('.pos-rel').attr('data-original-title',exvalue);
                        s_tr.find('.pos-rel').attr('data-percent',value+'%');
                        s_tr.find('.progress-bar').attr('style','width:'+width+'%;');
                        s_btn.html('<i class="ace-icon fa fa-stop "></i>');
                        s_btn.attr('data-click','true');
                        //更新tooltips内动态生成的DIV
                        s_tr.find('.tooltip-inner').html(exvalue);
                    }else{
                        s_tr.children('font').show();
                        s_tr.children('div').children('div').hide();
                        s_btn.html('<i class="ace-icon fa fa-play "></i>');
                        s_btn.attr('data-click','false');

                    }

                });
            }
        },'json');
    }
    function run(obj){

        var id = $(obj).attr('data-robot');
        var btn = $(obj);
        var tr = $('#progress'+id);
        if (btn.attr('data-click')=='true') {
            //if (!confirm("确定停止云采集任务吗？")) {return};
            btn.addClass("disabled");
            btn.removeAttr('data-click');
            var url = $(obj).attr('data-runstop');

            $.get(url);
            tr.children('div').children('div').hide();
            tr.children('font').show();
            setTimeout(function () {
                btn.removeClass("disabled");
                btn.html('<i class="ace-icon fa fa-play "></i>');
            }, 2000)

        }else{
            //if (!confirm("确定执行云采集任务吗？")) {return};
            btn.addClass("disabled");
            btn.html('<i class="ace-icon fa fa-spinner "></i>');
            //send request
            var url = $(obj).attr('data-run');
            $.get(url,function(res){
                if(res=="STARTRUN-OK"){
                    $(obj).attr('data-click','true');
                    tr.children('font').hide();
                    tr.children('div').children('div').show();
                    setTimeout(function () {
                        btn.removeClass("disabled");
                        btn.html('<i class="ace-icon fa fa-stop "></i>');
                    }, 2000)
                }else {
                    if(res=="INVALID-USERGROUP"){
                        Msg("机器人并发数已达上限");
                    }else if(res=="INVALID-TOKEN"){
                        Msg("机器人TOKEN异常，无法执行");
                    }else if(res=="INVALID-TYPE"){
                        Msg("机器人求类型异常，无法执行");
                    }else if(res=="INVALID-ROBOTID"){
                        Msg("机器人ID异常，无法执行");
                    }else if(res=="INVALID-STATUS-9"){
                        Msg("机器人状态为正常时才可执行");
                    }else if(res=="INVALID-STATUS"){
                        Msg("机器人状态异常，无法执行");
                    }
                    setTimeout(function () {
                        btn.removeClass("disabled");
                        btn.html('<i class="ace-icon fa fa-play "></i>');
                    }, 2000)
                }
            });

        }

    };
   setInterval("getPercent('.runstyle')",2000);
</script>

